#!/usr/bin/env bash

export DEBIAN_FRONTEND=noninteractive
ufw disable
apt update

SITE_PATH='/var/www/site'

# Create Database instance
mysql -u root -e "use mysql;update user set host = '%';"
mysql -u root -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '' WITH GRANT OPTION;"
mysql -u root -e "flush privileges;"
mysql -u root -e "create database drupal;"

# nginx config
# ln -s $SITE_PATH/nginx.conf /etc/nginx/sites-enabled/mysite.conf
cp $SITE_PATH/nginx.conf /etc/nginx/sites-enabled/mysite.conf
systemctl restart nginx

# composer
php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"
php composer-setup.php
chmod +x composer.phar
mv composer.phar /usr/local/bin/composer
cd $SITE_PATH/

# drupal console
curl https://drupalconsole.com/installer -L -o drupal.phar
mv drupal.phar /usr/local/bin/drupal
chmod +x /usr/local/bin/drupal

# redis
apt install redis
composer require drupal/redis
vendor/bin/drush en redis

# Post Up Message
echo "mysql: root / root"
echo "请访问 http://192.168.33.10/"